import React from 'react';
import './index.less';
import {connect} from "dva";
import Curd from "components/Curd";
import createColumns from "./columns";
import searchColumns from "./searchColumns";
import PropTypes from "prop-types";


@connect(({sellerEmployee}) => ({sellerEmployee}))
export default class extends Curd {

  static propTypes = {
    sellerId: PropTypes.number,
  };

  getNamespace() {
    return 'sellerEmployee';
  }

  getTableColumns() {
    return createColumns(this);
  }

  getSearchColumns() {
    return searchColumns;
  }

  componentDidMount() {
    const {sellerId} = this.props;
    this.init(sellerId);
    this.setState({filters: {sellerId}});
  }

  componentDidUpdate(prevProps, prevState, snapshot) {

    if(prevProps.sellerId != this.props.sellerId){

      const {sellerId} = this.props;
      this.init(sellerId);
      this.setState({filters: {sellerId}});
    }

  }

  init = (sellerId) => {

    !!sellerId &&
    this.dispatch({
      type: `${this.getNamespace()}/init`,
      payload: {
        notice: this.showMsg,
        filters: {sellerId}
      },
    });
  }

  addAndModify(value, record) {
    const {sellerId} = this.props;
    super.addAndModify({sellerId, ...value}, record);
  }

}
